<template>
	<view>
		<view style="height: 80px;"></view>
		<view style="text-align: center; height: 60px;">{{name}}</view>
		<view v-if="isVisp==1" style="text-align: center; height: 180px;">开通VIP:免费文字畅聊</view>
		<view v-if="isVisp==2" style="margin-left: 20rpx; margin-right: 20rpx; text-align: center; height: 220px;font-size: 26rpx;">为过滤非诚意用户,避免微商、酒托、广告等骚扰，打造 纯净私密的空间，保证产品持续稳定运营。需支付 一定费用，即可永久加入</view>
		<view style="height: 200px;"></view>
		<view v-if="issuccess==1" class="vip-kaitong" @click="open">继续</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
			name:'三天体验卡',
			isVisp:0,
			issuccess:1,
			}
		},
		onShow() {
			this.timers = setInterval(() => {
				this.chenname();
			}, 1000);
		 //    let zhifusuccess =uni.getStorageSync('zhifusuccess');
			// if(zhifusuccess=='1'){
			// 	this.issuccess=0;
			// }
			
		},
		onHide() {
		  uni.removeStorageSync('queryname');	
		},
		methods: {
			exitapp(){
				wx.exitMiniProgram({
				      success: function(res) {
				        console.log('退出')
				      },
				      fail: function(res) {
				        console.log('失败')
				      }
				 })
			},
			open(){
				let query =uni.getStorageSync('queryname');
				 this.apppushwxpay(query);	
			},
			async apppushwxpay(options)
			 {			 
				let wxopenid = uni.getStorageSync('wxopenid');																									
				let postParam ={};
				postParam.userId =options.userId;
				postParam.openid=wxopenid;
				postParam.price=options.price;
				postParam.type=	options.type;	 
				postParam.appId='wxff095378edaf00da';	
				postParam.projectId =options.projectId;
				// postParam.token =options.token;
				 //192.168.2.218  api.ptszyxx.com
			  console.log(JSON.stringify(postParam)+'*******66666333****');	
				uni.request({
					url: 'https://api.ptszyxx.com/api/JsApiController/recharge',					   
					method: 'POST',
					data: postParam,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						// 'token':options.token,
					},
					success: (res) => {
						console.log('*******88888*****'+JSON.stringify(res));
						let timeStamp = res.data.data.timeStamp;				
						let paySign = res.data.data.paySign;
						let appId = res.data.data.appId;
						let signType = res.data.data.signType;
						let nonceStr = res.data.data.nonceStr;
						
						wx.requestPayment({
										"timeStamp":timeStamp,
										"nonceStr":nonceStr,
										"package": res.data.data.package,
										"signType": signType,
										"paySign": paySign,
										"success": function(res) {
											//console.log('*************成功'+JSON.stringify(res));
										uni.setStorageSync('zhifusuccess', "1");	
										this.issuccess = 0;
											uni.showToast({
												title: '支付成功',
												duration: 3000
											})																																																										 
										},
										"fail": function(res) {
											//console.log('*************失败'+JSON.stringify(res));						
										},
										"complete": function(res) {
											if (res.errMsg == 'requestPayment:ok') {
																				 
											   uni.exitMiniProgram({
											   	success: function(res) {
											   		console.log('退出')
											   	},
											   	fail: function(res) {
											   		console.log('失败')							
											   	}
											   })									
											}										
						                   // console.log('********888888*****complete'+JSON.stringify(res));											
										}
									})									
					}
				})								 
			 },
			chenname(){
				let query =uni.getStorageSync('queryname');
				console.log(JSON.stringify(query)+'******888888***');
				if(query.type)
				{
					if(query.type==5)
					{
						this.isVisp =1;
						if(query.projectId==1)
						{
							this.name ='三天体验卡';
						}else if(query.projectId==2)
						{
							this.name ='月卡';
						}else if(query.projectId==3)
						{
							this.name ='半年卡';
						}else if(query.projectId==7)
						{
							this.name ='年卡';
						}
					}else if(query.type==4 || query.type==3)
					{
						this.isVisp =2;
						this.name ='门票';
					}else if(query.type==2)
					{
						if(query.projectId==101)
						{
							this.name ='1个VIP月';
						}else if(query.projectId==102)
						{
							this.name ='3个VIP月';
						}else if(query.projectId==103)
						{
							this.name ='12个VIP月';
						}
					}
				 console.log('*******55555555******'+this.name);	
				 clearInterval(this.timers);
				 
				}
			},
			
			
		}
		
		
		
		
	}
</script>
<style lang="scss" scoped>
	.vip-kaitong {
		margin: 0 auto;
		text-align: center;
		line-height: 120rpx;
		color: #a14617;
		width: 552rpx;
		height: 120rpx;
		background: linear-gradient(127deg, #FFF4DE 0%, #FFE6BA 100%, #FFE6BA 100%);
		
		border-radius: 60rpx;
	}

</style>